﻿namespace ACCOUNTING
{
    using ACCOUNTING.LVY.Business;
    using ACCOUNTING.My.Resources;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Sql;
    using System.Diagnostics;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    [DesignerGenerated]
    public class Frm_KetNoiCSDL : Form
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        [AccessedThroughProperty("CboDataBase")]
        private ComboBox _CboDataBase;
        [AccessedThroughProperty("CboServer")]
        private ComboBox _CboServer;
        [AccessedThroughProperty("CmdCancel")]
        private Button _CmdCancel;
        [AccessedThroughProperty("CmdOK")]
        private Button _CmdOK;
        [AccessedThroughProperty("CmdTestConnect")]
        private Button _CmdTestConnect;
        [AccessedThroughProperty("GroupBox1")]
        private GroupBox _GroupBox1;
        [AccessedThroughProperty("Label1")]
        private Label _Label1;
        [AccessedThroughProperty("Label2")]
        private Label _Label2;
        [AccessedThroughProperty("Label3")]
        private Label _Label3;
        [AccessedThroughProperty("Label4")]
        private Label _Label4;
        [AccessedThroughProperty("TxtPassword")]
        private TextBox _TxtPassword;
        [AccessedThroughProperty("TxtUserName")]
        private TextBox _TxtUserName;
        private IContainer components;

        [DebuggerNonUserCode]
        public Frm_KetNoiCSDL()
        {
            base.Load += new EventHandler(this.Frm_InitConnection_Load);
            base.KeyDown += new KeyEventHandler(this.Frm_KetNoiCSDL_KeyDown);
            List<WeakReference> list = __ENCList;
            lock (list)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.InitializeComponent();
        }

        public void BuildComboDatabase()
        {
            if ((this.CboServer.Text.Trim() != "") && (this.TxtUserName.Text.Trim() != ""))
            {
                string commandText = "";
                string connectionString = "";
                try
                {
                    connectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + this.TxtUserName.Text.Trim() + ";PWD=" + this.TxtPassword.Text.Trim() + ";Initial Catalog=master;Data Source=" + this.CboServer.Text;
                    this.CboDataBase.Items.Clear();
                    commandText = "SELECT Name FROM master.dbo.sysdatabases WHERE dbid > 6 ORDER BY Name";
                    DataTable table = DBHelper.ExecuteDataset(connectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
                    int num2 = table.Rows.Count - 1;
                    for (int i = 0; i <= num2; i++)
                    {
                        this.CboDataBase.Items.Add(RuntimeHelpers.GetObjectValue(table.Rows[i]["Name"]));
                    }
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    LVYModule.ShowWarning(exception.Message);
                    ProjectData.ClearProjectError();
                }
            }
        }

        public void BuildComboServer()
        {
            try
            {
                if (this.CboServer.Items.Count == 0)
                {
                    IEnumerator enumerator=null;
                    Cursor.Current = Cursors.WaitCursor;
                    DataTable dataSources = SqlDataSourceEnumerator.Instance.GetDataSources();
                    try
                    {
                        enumerator = dataSources.Rows.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            DataRow current = (DataRow) enumerator.Current;
                            if (current["InstanceName"].ToString() == "")
                            {
                                this.CboServer.Items.Add(RuntimeHelpers.GetObjectValue(current["ServerName"]));
                            }
                            else
                            {
                                this.CboServer.Items.Add(current["ServerName"].ToString() + @"\" + current["InstanceName"].ToString());
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                LVYModule.ShowWarning(exception.Message);
                ProjectData.ClearProjectError();
            }
        }

        public bool checkIvalid()
        {
            if (this.CboServer.Text.Trim() == "")
            {
                LVYModule.ShowWarning(modGeneral.Tranlated("Bạn phải nhập t\x00ean m\x00e1y chủ!", ""));
                this.CboServer.Focus();
                return false;
            }
            if (this.CboDataBase.Text.Trim() == "")
            {
                LVYModule.ShowWarning(modGeneral.Tranlated("Bạn phải nhập t\x00ean cơ sở dữ liệu!", ""));
                this.CboDataBase.Focus();
                return false;
            }
            if (this.TxtUserName.Text.Trim() == "")
            {
                LVYModule.ShowWarning(modGeneral.Tranlated("Bạn phải nhập t\x00ean t\x00ean người d\x00f9ng cơ sở dữ liệu!", ""));
                this.TxtUserName.Focus();
                return false;
            }
            return true;
        }

        private void CmdCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void CmdOK_Click(object sender, EventArgs e)
        {
            if (this.checkIvalid() && LVYModule.TestConnect(this.CboServer.Text, this.CboDataBase.Text, this.TxtUserName.Text, this.TxtPassword.Text))
            {
                LVYModule.SaveConnectionStringToXML(this.CboServer.Text.Trim(), this.CboDataBase.Text.Trim(), this.TxtUserName.Text.Trim(), this.TxtPassword.Text.Trim());
                LVYModule.InitConnection();
                this.Dispose();
            }
        }

        private void CmdTestConnect_Click(object sender, EventArgs e)
        {
            if (this.checkIvalid())
            {
                LVYModule.CheckConnection();
                if (LVYModule.TestConnect(this.CboServer.Text, this.CboDataBase.Text, this.TxtUserName.Text, this.TxtPassword.Text))
                {
                    LVYModule.ShowWarning(modGeneral.Tranlated("Kết nối th\x00e0nh c\x00f4ng! click n\x00fat OK để lưu v\x00e0o hệ thống!", ""));
                }
            }
        }

        [DebuggerNonUserCode]
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Frm_InitConnection_Load(object sender, EventArgs e)
        {
            this.BuildComboServer();
            this.CboServer.Text = LVYModule.ReadConnectionStringFromXML("ServerName");
            this.TxtPassword.Text = modGeneral.Decrypt(LVYModule.ReadConnectionStringFromXML("Password"));
            this.TxtUserName.Text = LVYModule.ReadConnectionStringFromXML("UserName");
            this.BuildComboDatabase();
            this.CboDataBase.Text = LVYModule.ReadConnectionStringFromXML("DatabaseName");
        }

        private void Frm_KetNoiCSDL_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
            {
                LVYModule.ShowHelp(@"QuanLyHeThong\Ket noi co so du lieu.mht");
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.GroupBox1 = new GroupBox();
            this.CboDataBase = new ComboBox();
            this.CboServer = new ComboBox();
            this.Label3 = new Label();
            this.TxtPassword = new TextBox();
            this.Label2 = new Label();
            this.TxtUserName = new TextBox();
            this.Label1 = new Label();
            this.Label4 = new Label();
            this.CmdTestConnect = new Button();
            this.CmdCancel = new Button();
            this.CmdOK = new Button();
            this.GroupBox1.SuspendLayout();
            this.SuspendLayout();
            this.GroupBox1.BackColor = Color.Transparent;
            this.GroupBox1.Controls.Add(this.CboDataBase);
            this.GroupBox1.Controls.Add(this.CboServer);
            this.GroupBox1.Controls.Add(this.Label3);
            this.GroupBox1.Controls.Add(this.TxtPassword);
            this.GroupBox1.Controls.Add(this.Label2);
            this.GroupBox1.Controls.Add(this.TxtUserName);
            this.GroupBox1.Controls.Add(this.Label1);
            this.GroupBox1.Controls.Add(this.Label4);
            Point point = new Point(3, 7);
            this.GroupBox1.Location = point;
            this.GroupBox1.Name = "GroupBox1";
            Size size = new Size(0x157, 0x8e);
            this.GroupBox1.Size = size;
            this.GroupBox1.TabIndex = 1;
            this.GroupBox1.TabStop = false;
            this.GroupBox1.Text = "Th\x00f4ng tin kết nối cơ sở dữ liệu SQL";
            this.CboDataBase.FormattingEnabled = true;
            point = new Point(0x60, 0x6b);
            this.CboDataBase.Location = point;
            this.CboDataBase.Name = "CboDataBase";
            size = new Size(0xe9, 0x15);
            this.CboDataBase.Size = size;
            this.CboDataBase.TabIndex = 4;
            this.CboServer.FormattingEnabled = true;
            point = new Point(0x60, 0x1c);
            this.CboServer.Location = point;
            this.CboServer.Name = "CboServer";
            size = new Size(0xe9, 0x15);
            this.CboServer.Size = size;
            this.CboServer.TabIndex = 0;
            this.Label3.AutoSize = true;
            point = new Point(9, 0x54);
            this.Label3.Location = point;
            this.Label3.Name = "Label3";
            size = new Size(0x35, 13);
            this.Label3.Size = size;
            this.Label3.TabIndex = 0x2b;
            this.Label3.Text = "Password";
            point = new Point(0x60, 0x51);
            this.TxtPassword.Location = point;
            this.TxtPassword.Name = "TxtPassword";
            this.TxtPassword.PasswordChar = '*';
            size = new Size(0xe9, 20);
            this.TxtPassword.Size = size;
            this.TxtPassword.TabIndex = 2;
            this.Label2.AutoSize = true;
            point = new Point(9, 0x3a);
            this.Label2.Location = point;
            this.Label2.Name = "Label2";
            size = new Size(0x3a, 13);
            this.Label2.Size = size;
            this.Label2.TabIndex = 0x29;
            this.Label2.Text = "User name";
            point = new Point(0x60, 0x37);
            this.TxtUserName.Location = point;
            this.TxtUserName.Name = "TxtUserName";
            size = new Size(0xe9, 20);
            this.TxtUserName.Size = size;
            this.TxtUserName.TabIndex = 1;
            this.Label1.AutoSize = true;
            point = new Point(9, 0x6d);
            this.Label1.Location = point;
            this.Label1.Name = "Label1";
            size = new Size(0x35, 13);
            this.Label1.Size = size;
            this.Label1.TabIndex = 0x27;
            this.Label1.Text = "Database";
            this.Label4.AutoSize = true;
            point = new Point(9, 0x1f);
            this.Label4.Location = point;
            this.Label4.Name = "Label4";
            size = new Size(0x43, 13);
            this.Label4.Size = size;
            this.Label4.TabIndex = 0x25;
            this.Label4.Text = "Server name";
            point = new Point(12, 0x9b);
            this.CmdTestConnect.Location = point;
            this.CmdTestConnect.Name = "CmdTestConnect";
            size = new Size(0x51, 0x18);
            this.CmdTestConnect.Size = size;
            this.CmdTestConnect.TabIndex = 8;
            this.CmdTestConnect.Text = "&Kết nối thử";
            this.CmdTestConnect.UseVisualStyleBackColor = true;
            point = new Point(0xf9, 0x9b);
            this.CmdCancel.Location = point;
            this.CmdCancel.Name = "CmdCancel";
            size = new Size(0x4f, 0x18);
            this.CmdCancel.Size = size;
            this.CmdCancel.TabIndex = 7;
            this.CmdCancel.Text = "&Tho\x00e1t";
            this.CmdCancel.UseVisualStyleBackColor = true;
            point = new Point(160, 0x9b);
            this.CmdOK.Location = point;
            this.CmdOK.Name = "CmdOK";
            size = new Size(0x4f, 0x18);
            this.CmdOK.Size = size;
            this.CmdOK.TabIndex = 5;
            this.CmdOK.Text = "&Chọn";
            this.CmdOK.UseVisualStyleBackColor = true;
            SizeF ef = new SizeF(6f, 13f);
            this.AutoScaleDimensions = ef;
            this.AutoScaleMode = AutoScaleMode.Font;
            this.BackgroundImage = ACCOUNTING.My.Resources.Resources.background;
            size = new Size(0x160, 0xb9);
            this.ClientSize = size;
            this.ControlBox = false;
            this.Controls.Add(this.CmdTestConnect);
            this.Controls.Add(this.CmdCancel);
            this.Controls.Add(this.CmdOK);
            this.Controls.Add(this.GroupBox1);
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.KeyPreview = true;
            this.Name = "Frm_KetNoiCSDL";
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "THIET LAP KET NOI CSDL";
            this.GroupBox1.ResumeLayout(false);
            this.GroupBox1.PerformLayout();
            this.ResumeLayout(false);
        }

        private void TxtPassword_LostFocus(object sender, EventArgs e)
        {
            if (this.CboServer.Text.Trim() != LVYModule.ReadConnectionStringFromXML("SERVERNAME"))
            {
                this.BuildComboDatabase();
            }
        }

        internal virtual ComboBox CboDataBase
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CboDataBase;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._CboDataBase = value;
            }
        }

        internal virtual ComboBox CboServer
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CboServer;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._CboServer = value;
            }
        }

        internal virtual Button CmdCancel
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CmdCancel;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.CmdCancel_Click);
                if (this._CmdCancel != null)
                {
                    this._CmdCancel.Click -= handler;
                }
                this._CmdCancel = value;
                if (this._CmdCancel != null)
                {
                    this._CmdCancel.Click += handler;
                }
            }
        }

        internal virtual Button CmdOK
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CmdOK;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.CmdOK_Click);
                if (this._CmdOK != null)
                {
                    this._CmdOK.Click -= handler;
                }
                this._CmdOK = value;
                if (this._CmdOK != null)
                {
                    this._CmdOK.Click += handler;
                }
            }
        }

        internal virtual Button CmdTestConnect
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CmdTestConnect;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.CmdTestConnect_Click);
                if (this._CmdTestConnect != null)
                {
                    this._CmdTestConnect.Click -= handler;
                }
                this._CmdTestConnect = value;
                if (this._CmdTestConnect != null)
                {
                    this._CmdTestConnect.Click += handler;
                }
            }
        }

        internal virtual GroupBox GroupBox1
        {
            [DebuggerNonUserCode]
            get
            {
                return this._GroupBox1;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._GroupBox1 = value;
            }
        }

        internal virtual Label Label1
        {
            [DebuggerNonUserCode]
            get
            {
                return this._Label1;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._Label1 = value;
            }
        }

        internal virtual Label Label2
        {
            [DebuggerNonUserCode]
            get
            {
                return this._Label2;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._Label2 = value;
            }
        }

        internal virtual Label Label3
        {
            [DebuggerNonUserCode]
            get
            {
                return this._Label3;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._Label3 = value;
            }
        }

        internal virtual Label Label4
        {
            [DebuggerNonUserCode]
            get
            {
                return this._Label4;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._Label4 = value;
            }
        }

        internal virtual TextBox TxtPassword
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtPassword;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.TxtPassword_LostFocus);
                if (this._TxtPassword != null)
                {
                    this._TxtPassword.LostFocus -= handler;
                }
                this._TxtPassword = value;
                if (this._TxtPassword != null)
                {
                    this._TxtPassword.LostFocus += handler;
                }
            }
        }

        internal virtual TextBox TxtUserName
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtUserName;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                this._TxtUserName = value;
            }
        }
    }
}

